<?php
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../DAO/MemberDAO.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../Util/Tool.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../Entity/Info/Schedule.php';
class MemberService
{

	public function createMember(BaseContext $context, ServiceResult $result,Schedule $schedule) {
		try 
		{
			$memberDao = new MemberDAO($context);
			$scheduleDao = new ScheduleDAO($context);
			
			$memberDao->create($schedule->getMemberDomain());

			$scheduleDao->create($schedule->getScheduleDomain());

			$result->setSuccess();				
			
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
			return false;
		}
	}
	public function updateMember(BaseContext $context, ServiceResult $result,MemberDomain $memberDomain) {
		try 
		{
			$memberDao = new MemberDAO($context);
			$memberDao->update($memberDomain);
			$result->setSuccess();				
			return true;	
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
			return false;
		}
	}
	public function deleteMember(BaseContext $context, ServiceResult $result,$memberID) {
		try 
		{
			$memberDao = new MemberDAO($context);
			$memberDao->deleteByOid($memberID);
			$result->setSuccess();				
			return true;	
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
			return false;
		}
	}
	public function findByOid(BaseContext $context, ServiceResult $result, $oid)
	{
		$memberDomain = null;
		try 
		{
			$memberDao = new MemberDAO($context);
			$memberDomain = $memberDao->findByOid($oid);
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		
		return $memberDomain;
	}
	
	public function findByDWONumber(BaseContext $context, ServiceResult $result, $dwoNumber)
	{
		$memberDomain = null;
		try 
		{
			$memberDao = new MemberDAO($context);
			$memberDomain = $memberDao->findByDwoNumber($dwoNumber);
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		
		return $memberDomain;
	}
	
	public function findByEmail(BaseContext $context, ServiceResult $result, $email)
	{
		$memberDomain = null;
		try 
		{
			$memberDao = new MemberDAO($context);
			$memberDomain = $memberDao->findByEmail($email);
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		
		return $memberDomain;
	}
	
	public function findAllMember(BaseContext $context, ServiceResult $result)
	{
		$memberDomainArr = null;
		try 
		{
			$memberDao = new MemberDAO($context);
			$memberDomainArr = $memberDao->findAllMember();
			$result->setSuccess();
		} 
		catch (Exception $e) 
		{
			$context->logException($e);
			$result->setException($e);
		}
		
		return $memberDomainArr;
	}
}